package com.tiantianyuegou.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.tiantianyuegou.R;

/**
 * 自定义dialog
 * 
 * @author sfshine
 */
public class MyDialogTextView {
	public static final int MODIFY_NAME = 0;
	public static final int MODIFY_Height = 1;
	public static final int MODIFY_Weight = 2;

	Context context;
	DialogCallback dialogCallback;
	Dialog dialog;
	public Button btn_cancel, btn_confirm;
	public TextView text_dialog_title, text_dialog_content;

	/**
	 * init the dialog
	 * 
	 * @return
	 */
	public MyDialogTextView(Context con, String dialog_title,
			String dialog_content) {
		this.context = con;
		dialog = new Dialog(context, R.style.myDialog);
		dialog.setContentView(R.layout.my_dialog_text);

		btn_cancel = (Button) dialog.findViewById(R.id.btn_cancel);
		btn_cancel.setTextColor(context.getResources().getColor(R.color.calendar_selected_day_bg));
		btn_confirm = (Button) dialog.findViewById(R.id.btn_confirm);
		btn_confirm.setTextColor(context.getResources().getColor(R.color.calendar_selected_day_bg));
		text_dialog_title = (TextView) dialog
				.findViewById(R.id.text_dialog_title);
		text_dialog_title.setText(dialog_title);
		text_dialog_title.setTextSize(18f);
		text_dialog_content = (TextView) dialog
				.findViewById(R.id.text_dialog_content);
		text_dialog_content.setTextSize(18f);
		text_dialog_content.setText(dialog_content);

		btn_confirm.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dialogCallback.dialogOpt();
				dismiss();
			}
		});
		btn_cancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
	}

	/**
	 * 设定一个interfack接口,使mydialog可以處理activity定義的事情
	 * 
	 * @author sfshine
	 */
	public interface DialogCallback {
		public void dialogOpt();
	}

	public void setDialogCallback(DialogCallback dialogCallback) {
		this.dialogCallback = dialogCallback;
	}

	public void show() {
		dialog.show();
	}

	public void hide() {
		dialog.hide();
	}

	public void dismiss() {
		dialog.dismiss();
	}
}
